import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true }
]
export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMapSeller = [
  {
    path: '/',
    component: Layout,
    redirect: '/seller/dashboard',
    name: 'Dashboard',
    // meta: { title: '瑞雅代理商', icon: 'example' },
    // hideen: false,
    children: [
      {
        path: '/seller/dashboard',
        name: 'Index',
        meta: { title: '首页', icon: 'example', roles: ['admin'] },
        component: () => import('@/views/seller/dashboard/index')
      }
    ]
  },
  {
    path: '/article',
    component: Layout,
    redirect: '/article/company',
    name: 'Article',
    meta: { title: '新闻', icon: 'example', roles: ['admin'] },
    children: [
      {
        path: 'company',
        name: 'Table',
        component: () => import('@/views/article/index'),
        meta: { title: '新闻列表', icon: 'table', roles: ['admin'] }
      },
      {
        path: 'quillEditor/:row',
        name: 'quillEditor',
        component: () => import('@/views/form/quillEditor'),
        meta: { title: '编辑文章', icon: 'table', roles: ['admin'] }
      }
    ]
  },
  {
    path: '/seller/orders',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Orders',
        component: () => import('@/views/seller/orders/index'),
        meta: { title: '订单', icon: 'table', roles: ['admin'] }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

export const asyncRouterMapMerchant = [
  {
    path: '/',
    component: Layout,
    redirect: '/merchant/dashboard',
    name: 'Dashboard',
    children: [
      {
        path: '/merchant/dashboard',
        name: 'Index',
        meta: { title: '首页', icon: 'example', roles: ['merchant'] },
        component: () => import('@/views/merchant/dashboard/index')
      }
    ]
  },
  {
    path: '/nasted',
    component: Layout,
    redirect: '/nasted/menu1',
    name: 'nasted',
    meta: { title: '分类', icon: 'example', roles: ['merchant'] },
    children: [
      {
        path: '/nasted/menu1',
        name: 'Menu1',
        // component: () => import('@/views/nested/menu1/index'),
        meta: { title: '分类一', icon: 'example' },
        redirect: '/merchant/nasted',
        children: [
          {
            path: '/nasted/menu1/menu1-1',
            name: 'Menu1-1',
            meta: { title: '分类1-1', icon: 'example' },
            component: () => import('@/views/nested/menu1/menu1-1/index')
          }
        ]
      },
      {
        path: '/nasted/menu2',
        name: 'quillEditor',
        component: () => import('@/views/nested/menu2/index'),
        meta: { title: '分类二', icon: 'example' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
export const asyncRouterMapEnterprise = [
  {
    path: '/',
    component: Layout,
    redirect: '/enterprise/dashboard',
    name: 'Dashboard',
    children: [
      {
        path: '/enterprise/dashboard',
        name: 'Index',
        meta: { title: '首页', icon: 'example', roles: ['enterprise'] },
        component: () => import('@/views/enterprise/dashboard/index')
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
